package com.dq.domain.sys.role;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @创建人 gewenzhen
 * @创建时间 2019/8/15
 * @描述 用户角色关系对照表
 */
@Data
@Entity
public class SysUserRole extends BaseEntity implements VO.ToVO {
    @ManyToOne
    private SysUser sysUser;
    @ManyToOne
    private SysRole sysRole;

    @Data
    @ApiModel(value = "用户角色视图")
    public static class Vo implements VO {
        @ApiModelProperty(value = "用户id")
        private Long userId;
        @ApiModelProperty(value = "角色id")
        private Long roleId;
        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty(value = "最新更新时间")
        private String lastModifyTime;
        @ApiModelProperty(value = "登陆名")
        private String userName;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.userId = this.sysUser.getId();
        vo.roleId = this.sysRole.getId();
        vo.userName = this.sysUser.getUsername();
        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.lastModifyTime = fmt(this.lastModifyTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        return vo;
    }
}
